package 我的Java学习_算法基础.day_05;

public class _077_去掉字符串中连接出现的k次的0 {
    public static void main(String[] args) {
        String s = "1000010";
        int k=3;
        System.out.println(remove0(s,k));
    }
    static String remove0(String s,int k){
        char[] arr = s.toCharArray();
        int count =0;//统计连续出现的0的次数
        StringBuilder sb = new StringBuilder();
        for(int i =0;i<s.length();i++){
            if(arr[i]=='0'){
                count++;
            }else{
                for(int j =0;j<count%k;j++){
                    sb.append("0");
                }
                sb.append(arr[i]);
                count=0;
            }
        }
        for(int j =0;j<count%k;j++){
            sb.append("0");
        }
        return sb.toString();
    }
}
